home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir24 / aprs308.zip / PLOTTER.BAS < prev    next >
BASIC Source File  |  1993-11-28  |  11KB  |  379 lines

  1. '***********************************************
  2. '*
  3. '*  Map digitizer program
  4. '*
  5. '*      By W7KKE
  6. '*
  7. '-----------------------------------------------
  8. '        Modification History
  9. '------------------------------------------------
  10. ' date    by        comments
  11. '------------------------------------------------
  12. ' 090193 W7KKE    Created program
  13. ' 112893 W7KKE    1. Fixed com port specification syntax.
  14. '                 2. Prohibited creation of a zero while building
  15. '                    map, otherwise ARPS thinks its an end of segment marker.
  16. '                 3. Clarified map scale selection menu.
  17. '***********************************************
  18. CLS
  19. PRINT
  20. PRINT "This program converts digitizer coordinates to latitude and longitude"
  21. PRINT
  22. PRINT "A Mercator projection chart is expected. Other types, such as Lambert Conformal,"
  23. PRINT "Conical, etc., will induce distortions."
  24. PRINT
  25. PRINT "It has not been tested with East Longitude or South Latitude."
  26. PRINT
  27. PRINT "The expected digitzer is a GE Calma which uses a 4000 x 4000 grid"
  28. PRINT "with grid origin in the lower left corner. The max number of points"
  29. PRINT "the program will take for each map section, i.e. coastline, road, etc.,"
  30. PRINT "is set to 100."
  31. PRINT
  32.  
  33. startit:
  34. 'Clear all arrays and variables
  35.    CLEAR , , 4000' Increase stack size. Default stack size is 2048 bytes.
  36.  
  37. 'Set comport parameters
  38.     port$ = "COM2:"
  39.     baud$ = "9600"
  40.     parity$ = "E"
  41.  
  42. ' Set number of data bits to be compatible with parity
  43.     IF parity$ <> "N" THEN dtabits$ = "7" ELSE dtabits$ = "8"
  44.  
  45. 'Zero variables
  46. segm = 0
  47. i = 0
  48.  
  49. 'Dimension arrays for map
  50. DIM segcolor(75)
  51. DIM seglable$(75)
  52. DIM hiposit(75)
  53. DIM pixlat(75, 200)
  54. DIM pixlong(75, 200)
  55.  
  56. 'Dimension labels
  57. DIM lablat(100)
  58. DIM lablong(100)
  59. DIM labrng(100)
  60. DIM N$(100)
  61.  
  62.  
  63. PRINT
  64. PRINT "The serial port is currently configured for ";
  65. PRINT port$; " at "; baud$; " baud "; parity$;
  66. PRINT " parity with "; dtabits$; "data bits."
  67. PRINT
  68. INPUT "Press <ENTER> to continue"; r$
  69. CLS
  70.  
  71. REM First establish scale on digitizer and x/y conversion.
  72. PRINT
  73. PRINT "Establish scale on digitizer."
  74. PRINT
  75. PRINT "The scale is established by two points, the first near the"
  76. PRINT "upper left corner, the second near the lower right corner."
  77. PRINT
  78. PRINT "Establish the upper left reference point:"
  79. INPUT "         Enter lat  (deg,min)"; latdeg1, latmin1
  80. INPUT "         Enter long (deg,min)"; longdeg1, longmin1
  81. PRINT
  82.  
  83. digion:
  84. REM Open digitizer port
  85. portspec$ = port$ + baud$ + "," + parity$ + "," + dtabits$ + ",1,asc,cd0,cs0,ds0,op0"
  86.    OPEN portspec$ FOR INPUT AS #2
  87.  
  88. penget:      PRINT "Place digitizer pen on upper left point."
  89.       INPUT #2, in$
  90.       SOUND 150, 5
  91.       REM Following causes loop for debugging digitizer board
  92.         REM PRINT MID$(in$, 2, 4); " "; RIGHT$(in$, 4)
  93.         REM  GOTO penget
  94.         digix1 = 4000 - VAL(MID$(in$, 2, 4))
  95.         digiy1 = VAL(RIGHT$(in$, 4))
  96.         PRINT "Digitizer reads "; digix1, digiy1; " for this point."
  97.         PRINT
  98.  
  99. PRINT "Establish the lower right reference point:"
  100. INPUT "         Enter lat  (deg,min)"; latdeg2, latmin2
  101. INPUT "         Enter long (deg,min)"; longdeg2, longmin2
  102. PRINT
  103. PRINT "Place digitizer pen on lower right point."
  104.       INPUT #2, in$
  105.       SOUND 150, 5
  106.         digix2 = 4000 - VAL(MID$(in$, 2, 4))
  107.         digiy2 = VAL(RIGHT$(in$, 4))
  108.         PRINT "Digitizer reads "; digix2, digiy2; " for this point."
  109.         PRINT
  110.  
  111. REM Find delta lat/long between reference points
  112. REM Convert lat & long to decimal values from degrees and minutes
  113.  
  114.         dlat1# = latdeg1 + (latmin1 / 60)
  115.         dlong1# = longdeg1 + (longmin1 / 60)
  116.  
  117.         dlat2# = latdeg2 + (latmin2 / 60)
  118.         dlong2# = longdeg2 + (longmin2 / 60)
  119.  
  120. REM Calculate the difference in lat long for conversion factor
  121.         deltalat# = dlat1# - dlat2#
  122.         deltalong# = dlong1# - dlong2#
  123.  
  124. REM Calculate the X/Y difference between the two reference points.
  125.         deltadigx = digix1 - digix2
  126.         deltadigy = digiy1 - digiy2
  127.  
  128. REM Calculate degrees per x/y unit
  129.         degx# = deltalong# / deltadigx
  130.         degy# = deltalat# / deltadigy
  131.  
  132.  
  133. REM Now set up APRS specific map data
  134. PRINT
  135. PRINT "Large areas (Continents)  6 pixels per degree"
  136. PRINT "Large States/Regions     60 pixels per degree"
  137. PRINT "States                  120 pixels per degree"
  138. PRINT "Cities                 1200 pixels per degree "
  139. PRINT "Neighborhoods          2400 pixels per degree"
  140. PRINT "Very fine detail       4800 pixels per degree"
  141. PRINT
  142. INPUT "Enter map scale in pixels"; pix
  143. PRINT
  144. PRINT "Using "; pix; " pixels per degree"
  145.  
  146. ' Calculate minimum zoom range to keep display from crashing
  147.  
  148.  IF pix <= 60 THEN minrng = 4
  149.  IF pix > 60 AND pix < 1200 THEN minrng = .5
  150.  IF pix >= 1200 THEN minrng = .25
  151.  
  152.  PRINT "Minimum map range will be "; minrng; " nm."
  153.  
  154.  
  155.  
  156. PRINT
  157. PRINT "Enter the origin lat/long for pixel 0/0 reference point"
  158. PRINT "(Use an even lat/long - no minutes, at upper left of map.)."
  159. INPUT "Enter latitude origin"; olat
  160. INPUT "Enter longitude origin"; olong
  161.  
  162. PRINT
  163.  
  164. centlatin:
  165. INPUT "Enter center latitude (deg,min)"; cenlatdeg, cenlatmin
  166.        IF cenlatdeg > 90 THEN GOTO centlatin
  167.        IF cenlatdeg < -90 THEN GOTO centlatin
  168.        IF centlatmin >= 60 THEN GOTO centlatin
  169.  
  170.  
  171. centlongin:
  172. INPUT "Enter center longitude (deg,min)"; cenlongdeg, cenlongmin
  173.        IF cenlogdeg > 180 THEN GOTO centlongin
  174.        IF cenlogdeg < -180 THEN GOTO centlongin
  175.        IF cenlongmin >= 60 THEN GOTO centlongin
  176.  
  177. 'Convert degrees & minutes to decimal degrees
  178.  
  179. dlat = cenlatdeg + (cenlatmin / 60)
  180. dlong = cenlongdeg + (cenlongmin / 60)
  181.  
  182. 'Save in unique variable name for file print routine
  183. cendlat = dlat
  184. cendlong = dlong
  185.  
  186. 'PRINT dlat, dlong   ' For debugging
  187.  
  188. PRINT
  189. INPUT "Enter map range (nm)"; maprng
  190. PRINT
  191.  
  192.  
  193. PRINT
  194. INPUT "Enter name for this map"; name$
  195. PRINT "Start entering points. Press 'F1' and tap digitizer pen on completion of data entry."
  196.      ON KEY(1) GOSUB getout
  197.  
  198. REM Start plotting points
  199. REM Continuous loop until F1 pressed
  200. enterseg:
  201. i = 0' zero individual point counter
  202. segm = segm + 1'Segment counter
  203. highseg = segm
  204. GOSUB getcolor
  205. segcolor(segm) = segcolor
  206. seglable$(segm) = r$
  207.  
  208.         PRINT "Point to first position on map"
  209.        KEY(1) ON
  210. getposits:
  211.        INPUT #2, in$
  212.         SOUND 150, 5
  213.         x = 4000 - VAL(MID$(in$, 2, 4))
  214.         y = VAL(RIGHT$(in$, 4))
  215.  
  216.         dlat# = ((y - digiy2) * degy#) + dlat2#
  217.         dlong# = ((x - digix2) * degx#) + dlong2#
  218.  
  219.         latmin = (dlat# - INT(dlat#)) * 60
  220.         longmin = (dlong# - INT(dlong#)) * 60
  221.  
  222. i = i + 1
  223. hiposit(segm) = i
  224. PRINT "Segment "; segm; " point "; i; " ";
  225.         PRINT INT(dlat#); " deg "; latmin; "'"; "  ";
  226.         PRINT INT(dlong#); " deg "; longmin; "'"
  227.  
  228. REM Convert lat/long to pixels
  229. GOSUB pixels:
  230.    pixlat(segm, i) = pixlat
  231.    pixlong(segm, i) = pixlong
  232.  
  233. GOTO getposits
  234. END  ' Should never get here
  235.  
  236. REM***********
  237.  
  238. labels:  'Routine to enter named labels on screen
  239. i = 0
  240. KEY(1) OFF
  241. CLS
  242. PRINT
  243. PRINT "Now starting entry of named geographic points for map."
  244.  
  245. entlabels:
  246.     i = i + 1
  247.     maxlabel = i
  248.     PRINT "Enter 'Q' for main menu"
  249.     INPUT "Label name"; N$(i)
  250.     IF N$(i) = "Q" OR N$ = "q" THEN GOTO getout
  251.     PRINT "Place pen at point and press. "
  252.        INPUT #2, in$
  253.         SOUND 150, 5
  254.         x = 4000 - VAL(MID$(in$, 2, 4))
  255.         y = VAL(RIGHT$(in$, 4))
  256.  
  257.         dlat# = ((y - digiy2) * degy#) + dlat2#
  258.         dlong# = ((x - digix2) * degx#) + dlong2#
  259.  
  260.         latmin = (dlat# - INT(dlat#)) * 60
  261.         longmin = (dlong# - INT(dlong#)) * 60
  262.  
  263.          dlat = dlat#
  264.          dlong = dlong#
  265.  
  266. PRINT "Segment "; segm; " point "; i; " ";
  267.         PRINT INT(dlat#); " deg "; latmin; "'"; "  ";
  268.         PRINT INT(dlong#); " deg "; longmin; "'"
  269.  
  270.    INPUT "Range scale you wish label to be displayed"; in
  271.    lablat(i) = dlat
  272.    lablong(i) = dlong
  273.    labrng(i) = in
  274.     PRINT
  275. GOTO entlabels
  276.  
  277. savsegs: 'Routine to save data to map file
  278.         CLS
  279.         CLOSE #2
  280.         INPUT "Enter name of map file (filename.map)"; r$
  281.         filename$ = r$
  282.         OPEN filename$ FOR OUTPUT AS #1
  283.  
  284.  
  285.         CLS
  286.         PRINT #1, olat; ", latitude of origin"
  287.         PRINT #1, olong; ", long of origin "
  288.         PRINT #1, pix; ", pixels per degree vert"
  289.         PRINT #1, cendlat; ", Latitude of map center"
  290.         PRINT #1, cendlong; ", Longitude of map center"
  291.         PRINT #1, maprng; ", Map range in miles"
  292.         PRINT #1, minrng; ", Min range for zoom function"
  293.         PRINT #1, name$
  294.  
  295.         FOR k = 1 TO highseg
  296.          PRINT #1, "0,0"   'End of line segment marker
  297.          PRINT #1, segcolor(k); ","; seglable$(k)
  298.            FOR l = 1 TO hiposit(k)
  299.             x = pixlong(k, l)
  300.             y = pixlat(k, l)
  301.             PRINT #1, STR$(x); ","; STR$(y)
  302.            NEXT l
  303.         NEXT k
  304.         PRINT #1, "0,-1"
  305.         PRINT #1, "0, Start map label data"
  306.  
  307.        'Print label data to file
  308.         FOR i = 1 TO maxlabel - 1
  309.           x = lablat(i)
  310.           y = lablong(i)
  311.           z = labrng(i)
  312.           PRINT #1, N$(i); ","; STR$(x); ","; STR$(y); ","; STR$(z)
  313. PRINT
  314.         NEXT i
  315.      CLOSE #1
  316.  
  317.  PRINT "Data saved as "; filename$
  318.  PRINT
  319. INPUT "Press enter to continue"; r$
  320. GOTO getout
  321.  
  322. END
  323.  
  324. 'SUBROUTINES
  325.  
  326. getcolor:  'Subroutine to select line segment color code
  327.  
  328.         PRINT "Use following color codes:"
  329.         PRINT "        Red (4) = secondary roads"
  330.         PRINT "        Bright red (12) = important highways"
  331.         PRINT "        Green (10) = interstates"
  332.         PRINT "        Light blue (11) = rivers & coastlines"
  333.         PRINT "        Orange (6) = city/county lines"
  334.         PRINT "        Purple (13) = special event routes"
  335.         PRINT
  336.         INPUT "Select color for this line segment"; segcolor
  337.         INPUT "Enter label for this segment"; r$
  338.  
  339.    RETURN
  340.  
  341. pixels:
  342.  
  343.         ' Find delta lat/long from zero/zero reference point
  344.        
  345.         deltalat = olat - dlat#
  346.         deltalong = olong - dlong#
  347.  
  348.         ' Convert the difference values into pixal values
  349.  
  350.      pixlat = INT(deltalat * pix)
  351.      pixlong = INT(deltalong * pix)
  352.      IF pixlat = 0 THEN
  353.        pixlat = 1
  354.        PRINT "Covernted pixal latitued from 0 to 1"
  355.      END IF
  356.      PRINT "Longitude/Latitude X/Y in pixels ="; pixlong; " / "; pixlat
  357.      PRINT
  358.  
  359.    RETURN
  360.  
  361. getout: 'Subroutine to getout of entry routines
  362.        
  363.         KEY(1) OFF
  364.         CLS
  365.         PRINT "Select:"
  366.         PRINT "     1) Enter another segment"
  367.         PRINT "     2) Enter named points for display on map (do after all segments)"
  368.         PRINT "     3) Save data to file"
  369.         PRINT "     4) Zero arrays and restart program"
  370.         PRINT "     5) Return to DOS"
  371.         INPUT in
  372.         ON in GOTO enterseg, labels, savsegs, startit, leave
  373.  
  374. leave: 'exit to DOS
  375.    CLOSE #2
  376.    SYSTEM
  377.    END
  378.  
  379.